/*
 * @Title: 姿美汇H5商城首页
 * @Author: JSL
 * @Date:   2018-10-11
 * @Last Modified by:   JSL
 * @Last Modified time: 2018-10-12
 */
var dataInfo = {},
  template = {
    init: function() {
      Vue.use(VueLazyload, {
        preLoad: 1.3,
        error: 'https://h5.meetao.com/img/product/init.png',
        loading: 'https://h5.meetao.com/img/product/init.png',
        attempt: 1
      });
      dataInfo.init = new Vue({
        el: '#app',
        data: {
          width: document.body.offsetWidth,
          tabData: [],
          swiperData: [],
          versions: versions,
          icon: {
            normal: '../img/index/shouhui.png',
            active: '../img/index/shouhong.png',
            normal1: '../img/index/gouhui.png',
            active1: '../img/index/gouhong.png',
            active2: '../img/index/myhong.png',
            normal2: '../img/index/myhui.png',
            active3: '../img/index/pthong.png',
            normal3: '../img/index/pthui.png',
            active4: "../img/index/votegoods.png",
            normal4: "../img/index/votegoodsgray.png",
          },
          active: 0,
          all: false, //loadOver - show
          isFx: 1,
          isDz: 0,
          page: 1,
          limit: 10,
          loading: false,
          isLoading: false,
          finished: false,
          listData: [], //商品集合
        },
        methods: {
          onLoad: function() {
            this.getProductDetails();
          },
          onRefresh: function() { //下拉刷新
            this.listData = [];
            this.page = 1;
            dataInfo.init.all = false;
            setTimeout(function() {
              dataInfo.init.getProductDetails();
            }, 500);
          },
          bannerJump: function(data) { //bannerJump
            if (data.linkRemark == 'product') { //商品 文章 视频 均为跳转内部地址 h5为跳转全链接地址
              jumpProductDetails(data.params);
            } else if (data.linkRemark == 'h5') {
              window.location.href = data.link;
            } else if (data.linkRemark == 'article') {

            } else if (data.linkRemark == 'video') {

            };
          },
          toProduct: function(data) { //toProduct
            jumpProductDetails(data);
          },
          tabJump: function(data) {
            location.href = "../html/productClassify.html?code=" + data.code + "&name=" + escape(data.name);
          },
          getProductDetails: function() { //获取商品数据
            ajaxTemplate(addressUrl + SERVICE.queryFxGoodsList, function(data) {
              console.log(data);
              var daTa = data.data.result;
              if (data.tag == 0) {
                dataInfo.init.listData = JSON.parse(JSON.stringify(dataInfo.init.listData.concat(daTa)));
                if (daTa.length < dataInfo.init.limit) {
                  console.log("无数据")
                  dataInfo.init.finished = true;
                  dataInfo.init.all = true;
                } else {
                  console.log('有数据')
                  dataInfo.init.finished = false;
                };
                dataInfo.init.loading = false;
                dataInfo.init.isLoading = false;
                //					是否要有秒杀
                //					daTa.forEach(function(item, index) {
                //						if(item.isKill !== 0) {
                //							dataInfo.init.listData.push(item);
                //						};
                //					});
                //					setTimeout(function() {
                //						var tid = "index" + (daTa.length - 1);
                //						$('#' + tid).ready(function() {
                //							$(".loadImgBox").addClass("rgba").hide();
                //						});
                //					}, 300);
              } else {
                dataInfo.init.$toast(data.errMsg);
              };
            }, {
              limit: dataInfo.init.limit,
              page: dataInfo.init.page++,
            });
          },
          getTab: function() {
            ajaxTemplate(addressTest + SERVICE.queryClassify, function(data) {
              console.log(data);
              if (data.tag == 0) {
                dataInfo.init.tabData = data.data.result;
              } else {
                dataInfo.init.$toast(data.errMsg);
              };
            }, {});
          },
          getBanner: function() {
            ajaxTemplate(addressUrl + SERVICE.queryBanner, function(data) {
              console.log(data);
              if (data.tag == 0) {
                dataInfo.init.swiperData = data.data.result;
              } else {
                dataInfo.init.$toast(data.errMsg);
              };
            }, {
              bannerCode: 'PAGE_DISTRIBUTION_HOME'
            });
          },
        },
      });
      dataInfo.init.getBanner();
      dataInfo.init.getTab();
    }
  };
template.init();
